package com.xyz.study.kafka.primary.producer;

import org.apache.kafka.clients.producer.*;

import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * 生产者
 *
 * @author XYZ
 * @version 1.0.0
 * @date 2020/6/29
 */
public class ProducerMain {

    private static KafkaProducer<String, String> kafkaProducer;

    private static String topic = "test-topic";

    private static int partition = 0;

    static{
        Properties properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.192.22:9092");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        kafkaProducer = new KafkaProducer<>(properties);
    }

    public static void main(String[] args) {
        ProducerRecord<String, String> producerRecord = new ProducerRecord(topic, partition, "MsgKey", "Hello World!");
        kafkaProducer.send(producerRecord);
        kafkaProducer.close();
    }
}
